import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import {InfoProvider} from "../../providers/InfoProvider";
import {HttpService} from "../../providers/HttpService";

/**
 * Generated class for the PubStrategyPage page.
 *
 * See http://ionicframework.com/docs/components/#navigation for more info
 * on Ionic pages and navigation.
 */
@IonicPage()
@Component({
    selector: 'page-pub-strategy',
    templateUrl: 'pub-strategy.html',
})
export class PubStrategyPage {

    user_info: any;

    strategy: any = {
        type: 1,
        content: null,
        user_id: null
    };

    constructor(public navCtrl: NavController, public navParams: NavParams,
                private infoProvider: InfoProvider,
                private httpService: HttpService) {
        this.user_info = this.infoProvider.getUserInfo();
        this.strategy.user_id = this.user_info.id;
    }

    ionViewDidLoad() {
        console.log('ionViewDidLoad PubStrategyPage');
    }

    onStrategySubmit() {
        console.log('onStrategySubmit: ', this.strategy);
        if (!this.strategy.content) {
            console.log('content missing');
            return;
        }

        this.httpService.instance()
            .setUrl('/strategy/addStrategy')
            .setBody(this.strategy)
            .postRequest()
            .then(res => {
                if (res.status == 0) {
                    this.navCtrl.pop();
                }
            });
    }
}
